package com.sh.rpc.loadbalancer;

import com.sh.rpc.spi.SpiLoader;

/**
 * 负载均衡工厂
 *
 * @author sh
 */
public class LoadBalanceFactory {
    static {
        SpiLoader.load(LoadBalancer.class);
    }


    /**
     * 默认值
     */
    private static final LoadBalancer DEFAULT_LOAD_BALANCER = new RoundRobinLoadBalancer();

    /**
     * 获取实例
     */
    public static LoadBalancer getInstance(String key) {
        LoadBalancer instance = SpiLoader.getInstance(LoadBalancer.class, key);
        return instance == null ? DEFAULT_LOAD_BALANCER : instance;
    }
}
